package com.nbsaas.boot.shopping.rest.convert;

import com.nbsaas.boot.shopping.data.entity.ShoppingCart;
import com.nbsaas.boot.shopping.api.domain.request.ShoppingCartRequest;

import org.springframework.beans.BeanUtils;
import com.nbsaas.boot.rest.api.Converter;
import com.nbsaas.boot.utils.BeanDataUtils;
            import com.nbsaas.boot.product.data.entity.Product;
            import com.nbsaas.boot.jpa.data.entity.User;
            import com.nbsaas.boot.shop.data.entity.Shop;
            import com.nbsaas.boot.product.data.entity.ProductSku;

/**
* 购物车请求对象转换成实体对象
*/

public class ShoppingCartEntityConvert  implements Converter<ShoppingCart, ShoppingCartRequest> {

    @Override
    public ShoppingCart convert(ShoppingCartRequest source) {
        ShoppingCart result = new ShoppingCart();
        BeanDataUtils.copyProperties(source, result);
                    if(source.getProduct()!=null){
                    Product product =new Product();
                    product.setId(source.getProduct());
                    result.setProduct(product);
                    }
                    if(source.getCreator()!=null){
                    User creator =new User();
                    creator.setId(source.getCreator());
                    result.setCreator(creator);
                    }
                    if(source.getShop()!=null){
                    Shop shop =new Shop();
                    shop.setId(source.getShop());
                    result.setShop(shop);
                    }
                    if(source.getSku()!=null){
                    ProductSku sku =new ProductSku();
                    sku.setId(source.getSku());
                    result.setSku(sku);
                    }
        return result;
    }
}

